package cn.itwangxiang.android.ui;

import java.util.ArrayList;
import java.util.List;

import cn.itwangxiang.android.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.PagerTitleStrip;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;

public class DemoUIViewPager extends Activity {
	
	private ViewPager vPager;
	
	private PagerTitleStrip pagerTitleStrip;
	
	private PagerTabStrip pagerTabStrip;
	
	private List<View> list;
	
	private List<String> titleList;
	
	private List tabList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.demo_ui_viewpager);
		
		vPager = (ViewPager) findViewById(R.id.viewpager);
		//pagerTitleStrip = (PagerTitleStrip) findViewById(R.id.pagertitle);
		pagerTabStrip = (PagerTabStrip) findViewById(R.id.pagertab);
		
		View view1 = LayoutInflater.from(DemoUIViewPager.this).inflate(R.layout.demo_layout_table, null);
		
		View view2 = LayoutInflater.from(DemoUIViewPager.this).inflate(R.layout.demo_layout_relative, null);
		
		View view3 = LayoutInflater.from(DemoUIViewPager.this).inflate(R.layout.demo_layout_frame, null);
		
		list = new ArrayList<View>();
		list.add(view1);
		list.add(view2);
		list.add(view3);
		
		titleList = new ArrayList<String>();
		titleList.add("layout_table");
		titleList.add("layout_relative");
		titleList.add("layout_frame");
		
		tabList = new ArrayList();
		pagerTabStrip.setTabIndicatorColor(Color.RED);  
        pagerTabStrip.setTextColor(Color.RED);  
        pagerTabStrip.setClickable(false);  
        pagerTabStrip.setTextSpacing(40);  
        pagerTabStrip.setBackgroundColor(Color.GRAY);  
        pagerTabStrip.setDrawFullUnderline(true); 
		
		vPager.setAdapter(new MyPagerAdapter());
		
	}
		
	class MyPagerAdapter extends PagerAdapter {

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			return arg0==arg1;
		}
		
		@Override
		public void destroyItem(View container, int position, Object object) {
			((ViewPager)container).removeView(list.get(position));
		}
		
		@Override
		public CharSequence getPageTitle(int position) {
			return titleList.get(position);
		}
		
		@Override
		public Object instantiateItem(View container, int position) {
			((ViewPager)container).addView(list.get(position));
			return list.get(position);
		}
		
		
	}

}
